www.gusucode.com > VC++ 客户管理系统(SQL Serve)-源码程序 > VC++ 客户管理系统(SQL Serve)-源码程序/code/Program/qyxz.cpp
// qyxz.cpp : implementation file // #include "stdafx.h" #include "khmanager.h" #include "qyxz.h" #include "ado.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif int qyxzclnum=0; int qyxzxiugai=0; ///////////////////////////////////////////////////////////////////////////// // qyxz dialog qyxz::qyxz(CWnd* pParent /*=NULL*/) : CDialog(qyxz::IDD, pParent) { //{{AFX_DATA_INIT(qyxz) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void qyxz::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(qyxz) DDX_Control(pDX, IDC_LIST1, m_list); DDX_Control(pDX, IDC_EDIT3, m_edit3); DDX_Control(pDX, IDC_EDIT2, m_edit2); DDX_Control(pDX, IDC_EDIT1, m_edit1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(qyxz, CDialog) //{{AFX_MSG_MAP(qyxz) ON_COMMAND(ID_ADD, OnAdd) ON_COMMAND(ID_DELETE, OnDelete) ON_COMMAND(ID_EXIT, OnExit) ON_COMMAND(ID_SAVE, OnSave) ON_COMMAND(ID_UPDATE, OnUpdate) ON_COMMAND(ID_CANCEL, OnCancel) ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // qyxz message handlers BOOL qyxz::OnInitDialog() { CDialog::OnInitDialog(); imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1))); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2))); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON3))); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON4))); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON5))); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON10))); CString s; TCHAR *pString; menu.LoadMenu(IDR_lxrxx); toolbar.EnableAutomation(); toolbar.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,ID_TOOLBAR); toolbar.SetImageList(&imagelist); int i; for(i=0;i<8;i++) { button[i].dwData=0; button[i].fsState=TBSTATE_ENABLED; button[i].fsStyle=TBSTYLE_BUTTON; } button[5].fsStyle=TBSTYLE_SEP; button[0].idCommand=ID_ADD; button[0].iBitmap=0; button[1].idCommand=ID_UPDATE; button[1].iBitmap=1; button[2].idCommand=ID_DELETE; button[2].iBitmap=2; button[3].idCommand=ID_SAVE; button[3].iBitmap=3; button[4].idCommand=ID_CANCEL; button[4].iBitmap=4; button[6].idCommand=ID_EXIT; button[6].iBitmap=5; for(i=0;i<8;i++) { s.LoadString(i+IDS_21); int nStringLength= s.GetLength() + 1; pString = s.GetBufferSetLength(nStringLength); button[i].iString =toolbar.AddStrings(pString); s.ReleaseBuffer(); } toolbar.AddButtons(7,button); toolbar.AutoSize(); toolbar.SetStyle(TBSTYLE_FLAT|CCS_TOP); toolbar.EnableButton(ID_SAVE,false); toolbar.EnableButton(ID_CANCEL,false); m_list.ModifyStyle(0L,LVS_REPORT); // m_list.ModifyStyle(0L,LVS_SINGLESEL); m_list.ModifyStyle(0L,LVS_SHOWSELALWAYS); m_list.ModifyStyle(0L,LVS_NOSORTHEADER); m_list.SetExtendedStyle(LVS_EX_GRIDLINES| LVS_EX_FULLROWSELECT| LVS_EX_HEADERDRAGDROP| LVS_EX_ONECLICKACTIVATE); m_list.InsertColumn(0,"企业性质编号"); m_list.InsertColumn(1,"企业性质名称"); m_list.InsertColumn(2,"备注信息"); m_list.SetColumnWidth(0,100); m_list.SetColumnWidth(1,100); m_list.SetColumnWidth(2,100); this->loadlist(); this->enbalewin(false); this->datatotext(); this->texttowin(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void qyxz::OnAdd() { this->enbalewin(true); this->enablebutton(false); this->clearall(); this->autonum(); } void qyxz::OnCancel() { this->enbalewin(false); this->enablebutton(true); qyxzxiugai=0; this->datatotext(); this->texttowin(); } void qyxz::OnDelete() { ado rst; CString ss,aa; this->m_edit1.GetWindowText(aa); if(aa.IsEmpty()) {MessageBox("不能为空","提示"); return;} if(MessageBox("删除后数据将丢失","提示",MB_YESNO)==IDYES) { ss.Format("delete from tb_Client_qyxz where qyxz_id = '%s'",aa); rst.ExecuteSQL(ss); //rst.close(); m_list.DeleteAllItems(); this->loadlist(); this->datatotext(); this->texttowin(); } } void qyxz::OnExit() { this->EndDialog(true); } void qyxz::OnSave() { ado rst; this->wintotext(); CString ss,srept; srept.Format("select * from tb_Client_qyxz where qyxz_xzmc='%s'",edit2); rst.rstOpen(srept); if(rst.GetRecordCount()>0) { MessageBox("这个性质名称已经存在了","提示"); return; } if(qyxzxiugai==1) {ss.Format("UPDATE tb_Client_qyxz set qyxz_xzmc='%s',qyxz_bz='%s' where qyxz_id='%s'",edit2,edit3,edit1);} else {ss.Format("INSERT INTO tb_Client_qyxz values('%s','%s','%s')",edit1,edit2,edit3);} rst.ExecuteSQL(ss); // rst.close(); m_list.DeleteAllItems(); this->loadlist(); this->datatotext(); this->texttowin(); this->enbalewin(false); this->enablebutton(true); qyxzxiugai=0; } void qyxz::OnUpdate() { CString ss,aa; this->m_edit1.GetWindowText(aa); if(aa.IsEmpty()) {MessageBox("不能为空","提示"); return;} this->enbalewin(true); this->enablebutton(false); qyxzxiugai=1; } void qyxz::clearall() { this->m_edit1.SetWindowText(""); this->m_edit2.SetWindowText(""); this->m_edit3.SetWindowText(""); } void qyxz::enablebutton(bool butn) { toolbar.EnableButton(ID_ADD,butn); toolbar.EnableButton(ID_UPDATE,butn); toolbar.EnableButton(ID_DELETE,butn); toolbar.EnableButton(ID_SAVE,!butn); toolbar.EnableButton(ID_CANCEL,!butn); } void qyxz::enbalewin(bool wi) { this->m_edit1.EnableWindow(wi); this->m_edit2.EnableWindow(wi); this->m_edit3.EnableWindow(wi); } void qyxz::texttowin() { this->m_edit1.SetWindowText(edit1); this->m_edit2.SetWindowText(edit2); this->m_edit3.SetWindowText(edit3); } void qyxz::wintotext() { this->m_edit1.GetWindowText(edit1); this->m_edit2.GetWindowText(edit2); this->m_edit3.GetWindowText(edit3); } void qyxz::datatotext() { edit1=m_list.GetItemText(qyxzclnum,0); edit2=m_list.GetItemText(qyxzclnum,1); edit3=m_list.GetItemText(qyxzclnum,2); } void qyxz::loadlist() { ado rst; rst.rstOpen("select * from tb_Client_qyxz"); int recordcount=rst.GetRecordCount(); int ii; for(ii=1;ii<=recordcount;ii++) { m_list.InsertItem(ii-1,""); m_list.SetItemText(ii-1,0,rst.GetFieldValue("qyxz_id")); m_list.SetItemText(ii-1,1,rst.GetFieldValue("qyxz_xzmc")); m_list.SetItemText(ii-1,2,rst.GetFieldValue("qyxz_bz")); rst.Move(ii); } rst.close(); } void qyxz::autonum() { ado rst3; rst3.rstOpen("select * from tb_Client_qyxz"); if(rst3.GetRecordCount()==0) { this->m_edit1.SetWindowText("XZ001"); this->m_edit1.EnableWindow(false); return; } rst3.MoveLast(); CString mm=rst3.GetFieldValue("qyxz_id"); int xuhao=atoi(mm.Right(3)); xuhao+=1; mm.Format("XZ%03d",xuhao); this->m_edit1.EnableWindow(false); this->m_edit1.SetWindowText(mm); rst3.close(); } void qyxz::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) { qyxzclnum=m_list.GetHotItem(); if(qyxzclnum<0) {return;} this->datatotext(); this->texttowin(); this->enbalewin(false); this->enablebutton(true); *pResult = 0; } BOOL qyxz::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class return CDialog::PreTranslateMessage(pMsg); }